package systemsnapshot.svn;

//Imports
import java.awt.Toolkit;
import javax.swing.JOptionPane;



/**
 *
 * @author eladh, alaah
 */ 
public class SystemSnapshotSVNUI extends javax.swing.JFrame {
    
    public Logic logical = null;

    // Constructor 
    public SystemSnapshotSVNUI() {
        initComponents();
        hideWaitPanel();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        genHTMLBtn = new javax.swing.JButton();
        systemSnapshotLabel = new javax.swing.JLabel();
        pleaseWaitMsgLabel1 = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();
        imgHolder = new javax.swing.JLabel();
        jMenuBar = new javax.swing.JMenuBar();
        jMenuFile = new javax.swing.JMenu();
        jMenuExit = new javax.swing.JMenuItem();
        jMenuAbout = new javax.swing.JMenu();
        jMenuVersion = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("System Snapshot");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setForeground(java.awt.Color.blue);
        setIconImage(Toolkit.getDefaultToolkit().getImage(SystemSnapshotSVNUI.class.getResource("tblogo.png")));
        setIconImages(getIconImages());

        genHTMLBtn.setText("Generate HTML");
        genHTMLBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                genHTMLBtnActionPerformed(evt);
            }
        });

        systemSnapshotLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        systemSnapshotLabel.setText("Windows System Information Snapshot Utility");

        pleaseWaitMsgLabel1.setText("Gathering the information may take a while");

        imgHolder.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        imgHolder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/systemsnapshot/svn/ml.png"))); // NOI18N

        jMenuFile.setText("File");

        jMenuExit.setText("Exit");
        jMenuExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuExitActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuExit);

        jMenuBar.add(jMenuFile);

        jMenuAbout.setText("About");

        jMenuVersion.setText("Version");
        jMenuVersion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuVersionActionPerformed(evt);
            }
        });
        jMenuAbout.add(jMenuVersion);

        jMenuBar.add(jMenuAbout);

        setJMenuBar(jMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(systemSnapshotLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(imgHolder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 12, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 7, Short.MAX_VALUE)
                                .addComponent(pleaseWaitMsgLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(85, 85, 85)
                        .addComponent(genHTMLBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imgHolder)
                .addGap(18, 18, 18)
                .addComponent(systemSnapshotLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pleaseWaitMsgLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(genHTMLBtn)
                .addGap(18, 18, 18))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-310)/2, (screenSize.height-256)/2, 310, 256);
    }// </editor-fold>//GEN-END:initComponents

    private void genHTMLBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genHTMLBtnActionPerformed
       try{
            if (genHTMLBtn.getText().equals("Generate HTML")){
                logical = new Logic();
                logical.start();
                genHTMLBtn.setText("Stop");
                showWaitPanel();
            }
            else{
                    logical.stopThread();
                    logical = null;
                    genHTMLBtn.setText("Generate HTML");
                    hideWaitPanel();
                    JOptionPane.showMessageDialog(null, "Gathering the information was stopped.", "Proccess stopped", JOptionPane.INFORMATION_MESSAGE);
            }
        } 
       catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error terminating process", "Proccess interrupted", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_genHTMLBtnActionPerformed

    private void jMenuVersionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuVersionActionPerformed
        JOptionPane.showMessageDialog(null, "System-Snapshot Version: " + Logic.getVersion(), "Application Version", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_jMenuVersionActionPerformed

    private void jMenuExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuExitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuExitActionPerformed
                                   

  
    public void showWaitPanel(){
        pleaseWaitMsgLabel1.setVisible(true);
        jProgressBar1.setVisible(true);
        jProgressBar1.setIndeterminate(true);
    }
    
    private void hideWaitPanel(){
        pleaseWaitMsgLabel1.setVisible(false);
        jProgressBar1.setIndeterminate(false);
        jProgressBar1.setVisible(true);
    }
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (Exception ex) {
            java.util.logging.Logger.getLogger(SystemSnapshotSVNUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new SystemSnapshotSVNUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton genHTMLBtn;
    private javax.swing.JLabel imgHolder;
    private javax.swing.JMenu jMenuAbout;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JMenuItem jMenuExit;
    private javax.swing.JMenu jMenuFile;
    private javax.swing.JMenuItem jMenuVersion;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JLabel pleaseWaitMsgLabel1;
    private javax.swing.JLabel systemSnapshotLabel;
    // End of variables declaration//GEN-END:variables

}